namespace QMVnSoft.Lists
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.Controls.ChildGridControls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmPBCHSPEditor : FormListEditor
    {
        private BtnControl btnAllocate;
        private BtnControl btnGetValue;
        private SearchColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private NumericColumn Column3;
        private NumericColumn Column4;
        private IContainer components;
        private GridDetail grdDetail;
        private LabelControl labelControl2;
        private LabelControl lblDesc_EN;
        private LabelControl lblDien_Giai;
        private LabelControl lblMa_Sp;
        private LabelControl lblMa_Yt;
        private LabelControl lblTTien_Nt0;
        private LabelControl lblTTien_PB;
        private DataTable oDataTable;
        private DataTable oDetailTable;
        private DmPBSPDataAccess oMethod;
        private TextControl txtDesc_EN;
        private TextControl txtDien_Giai;
        private TextSearch txtMa_Sp;
        private TextSearch txtMa_Yt;
        private TextControl txtTen_Sp;
        private TextControl txtTen_Yt;
        private TextNumeric txtTTien_Nt0;
        private TextNumeric txtTTien_PB;

        public FormDmPBCHSPEditor()
        {
            this.oMethod = new DmPBSPDataAccess();
            this.InitializeComponent();
        }

        public FormDmPBCHSPEditor(object poUserDefined1, object poUserDefined2, object poUserDefined3) : base(poUserDefined1, poUserDefined2, poUserDefined3)
        {
            this.oMethod = new DmPBSPDataAccess();
            this.InitializeComponent();
        }

        private bool AddNewRow(bool pb_Inserted)
        {
            if ((this.grdDetail.CurrentRow == null) || (this.grdDetail.CurrentRow.DataBoundItem == null))
            {
                return false;
            }
            DataRow row1 = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
            if (this.grdDetail.CurrentRow.Index != (this.grdDetail.Rows.Count - 1))
            {
                return false;
            }
            this.grdDetail.EndEdit();
            DataRow row = this.oDetailTable.NewRow();
            row["He_So"] = 0;
            row["Tien_PB"] = 0;
            this.oDetailTable.Rows.Add(row);
            BindingSource dataSource = this.grdDetail.DataSource as BindingSource;
            dataSource.Position++;
            return true;
        }

        private void btnAllocate_Click(object sender, EventArgs e)
        {
            if (this.oDetailTable.Rows.Count == 0)
            {
                MessageBox.Show("Chưa nhập hệ số phân bổ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (((this.txtTTien_Nt0.NumericValue == 0M) || (this.oDataTable == null)) || (this.oDataTable.Rows.Count == 0))
            {
                MessageBox.Show("Chưa có giá trị phân bổ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                decimal num = 0M;
                foreach (DataRow row in this.oDetailTable.Rows)
                {
                    if (row.RowState != DataRowState.Deleted)
                    {
                        num += (decimal) row["He_So"];
                    }
                }
                if (num == 0M)
                {
                    MessageBox.Show("Chưa nhập hệ số phân bổ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    decimal num2 = 0M;
                    decimal num3 = 0M;
                    DataRow row2 = null;
                    foreach (DataRow row3 in this.oDetailTable.Rows)
                    {
                        if (row3.RowState != DataRowState.Deleted)
                        {
                            row3["Tien_PB"] = decimal.Round((((decimal) row3["He_So"]) * this.txtTTien_Nt0.NumericValue) / num, AppInstance.LCAmountDecimals);
                            num2 += (decimal) row3["Tien_PB"];
                            if (((decimal) row3["Tien_PB"]) > num3)
                            {
                                num3 = (decimal) row3["Tien_PB"];
                                row2 = row3;
                            }
                        }
                    }
                    if (num2 != this.txtTTien_Nt0.NumericValue)
                    {
                        row2["Tien_PB"] = ((decimal) row2["Tien_PB"]) + (this.txtTTien_Nt0.NumericValue - num2);
                    }
                    this.txtTTien_PB.Value = this.txtTTien_Nt0.Value;
                }
            }
        }

        private void btnGetValue_Click(object sender, EventArgs e)
        {
            object obj2 = 0;
            this.oDataTable = this.oMethod.PhanBo_CHSP(AppInstance.Subsidiary, base.UserDefined1, base.UserDefined2, this.txtMa_Sp.Value, this.txtMa_Yt.Value, ref obj2);
            this.txtTTien_Nt0.Value = obj2;
        }

        private DataTable CreateInvoice()
        {
            if ((this.oDataTable == null) || (this.oDataTable.Rows.Count == 0))
            {
                MessageBox.Show("Chưa có giá trị phân bổ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return null;
            }
            DataTable table = new DataTable();
            DataColumn column = new DataColumn("Stt0_No", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Stt0_Co", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Tk_No", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Tk_Co", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Tien", typeof(decimal));
            table.Columns.Add(column);
            table.PrimaryKey = new DataColumn[] { table.Columns["Tk_No"], table.Columns["Tk_Co"] };
            foreach (DataRow row2 in this.oDataTable.Rows)
            {
                if (!string.IsNullOrEmpty(row2["Tk_No"].ToString()))
                {
                    object[] keys = new object[] { base.UserDefined3, row2["Tk_No"] };
                    DataRow row = table.Rows.Find(keys);
                    if (row == null)
                    {
                        row = table.NewRow();
                        row["Stt0_No"] = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
                        row["Stt0_Co"] = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
                        row["Tk_No"] = base.UserDefined3;
                        row["Tk_Co"] = row2["Tk_No"];
                        row["Tien"] = 0;
                    }
                    row["Tien"] = ((decimal) row["Tien"]) + ((decimal) row2["Tien"]);
                    if (row.RowState == DataRowState.Detached)
                    {
                        table.Rows.Add(row);
                    }
                }
            }
            return table;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_CellBottomLeftLeaved(object sender, EventArgs e)
        {
            if (((this.grdDetail.Rows.Count == 1) || !string.IsNullOrEmpty(((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row["Ma_Sp"].ToString())) || !string.IsNullOrEmpty(base.ActiveControl.Text))
            {
                this.grdDetail.UserMoveNextCell = GridDetail.MoveNextType.NextCell;
            }
            else
            {
                this.btnGetValue.Focus();
                this.grdDetail.UserMoveNextCell = GridDetail.MoveNextType.DeleteCurrentRow;
            }
        }

        private void grdDetail_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                this.Sum();
            }
        }

        private void grdDetail_CellRightLeaved(object sender, EventArgs e)
        {
            if (this.AddNewRow(false))
            {
                this.grdDetail.UserMoveNextCell = GridDetail.MoveNextType.FirstCell;
            }
            else
            {
                this.grdDetail.UserMoveNextCell = GridDetail.MoveNextType.FirstCellNextRow;
            }
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDmPBCHSPEditor));
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
            this.txtMa_Sp = new QMVnSoft.Controls.TextSearch();
            this.txtTen_Sp = new QMVnSoft.Controls.TextControl();
            this.lblMa_Yt = new QMVnSoft.Controls.LabelControl();
            this.txtTen_Yt = new QMVnSoft.Controls.TextControl();
            this.txtMa_Yt = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Sp = new QMVnSoft.Controls.LabelControl();
            this.lblDesc_EN = new QMVnSoft.Controls.LabelControl();
            this.lblDien_Giai = new QMVnSoft.Controls.LabelControl();
            this.txtDesc_EN = new QMVnSoft.Controls.TextControl();
            this.txtDien_Giai = new QMVnSoft.Controls.TextControl();
            this.grdDetail = new QMVnSoft.Controls.GridDetail();
            this.Column1 = new QMVnSoft.Controls.ChildGridControls.SearchColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.Column4 = new QMVnSoft.Controls.ChildGridControls.NumericColumn();
            this.btnAllocate = new QMVnSoft.Controls.BtnControl();
            this.btnGetValue = new QMVnSoft.Controls.BtnControl();
            this.txtTTien_Nt0 = new QMVnSoft.Controls.TextNumeric();
            this.lblTTien_Nt0 = new QMVnSoft.Controls.LabelControl();
            this.lblTTien_PB = new QMVnSoft.Controls.LabelControl();
            this.txtTTien_PB = new QMVnSoft.Controls.TextNumeric();
            this.labelControl2 = new QMVnSoft.Controls.LabelControl();
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).BeginInit();
            this.SuspendLayout();
            // 
            // lblPhan_Loai
            // 
            this.lblPhan_Loai.Location = new System.Drawing.Point(12, 434);
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.Location = new System.Drawing.Point(123, 431);
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.Location = new System.Drawing.Point(251, 431);
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.Location = new System.Drawing.Point(379, 431);
            // 
            // txtMa_Sp
            // 
            this.txtMa_Sp.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Sp.CheckTextSearched = false;
            this.txtMa_Sp.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Sp.EmptyIsValid = true;
            this.txtMa_Sp.FieldDisplay = "Ten_Sp";
            this.txtMa_Sp.FirstFilter = "SP_CT = \'S\' AND Loai_Sp = \'K\'";
            this.txtMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Sp.FoundIsValid = true;
            this.txtMa_Sp.Location = new System.Drawing.Point(97, 49);
            this.txtMa_Sp.MaxLength = 32;
            this.txtMa_Sp.Name = "txtMa_Sp";
            this.txtMa_Sp.OldValue = null;
            this.txtMa_Sp.Size = new System.Drawing.Size(111, 20);
            this.txtMa_Sp.TabIndex = 1;
            this.txtMa_Sp.TableName = "DMSP";
            this.txtMa_Sp.TextDisplay = this.txtTen_Sp;
            this.txtMa_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Sp.Value = ((object)(resources.GetObject("txtMa_Sp.Value")));
            // 
            // txtTen_Sp
            // 
            this.txtTen_Sp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Sp.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Sp.CheckTextSearched = false;
            this.txtTen_Sp.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Enabled = false;
            this.txtTen_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Sp.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Location = new System.Drawing.Point(214, 52);
            this.txtTen_Sp.Name = "txtTen_Sp";
            this.txtTen_Sp.OldValue = null;
            this.txtTen_Sp.Size = new System.Drawing.Size(570, 13);
            this.txtTen_Sp.TabIndex = 86;
            this.txtTen_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Sp.Value = ((object)(resources.GetObject("txtTen_Sp.Value")));
            // 
            // lblMa_Yt
            // 
            this.lblMa_Yt.AutoSize = true;
            this.lblMa_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Yt.Location = new System.Drawing.Point(9, 31);
            this.lblMa_Yt.Name = "lblMa_Yt";
            this.lblMa_Yt.Size = new System.Drawing.Size(39, 14);
            this.lblMa_Yt.TabIndex = 83;
            this.lblMa_Yt.Text = "Yếu tố";
            // 
            // txtTen_Yt
            // 
            this.txtTen_Yt.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Yt.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Yt.CheckTextSearched = false;
            this.txtTen_Yt.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Yt.Enabled = false;
            this.txtTen_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Yt.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Yt.Location = new System.Drawing.Point(214, 31);
            this.txtTen_Yt.Name = "txtTen_Yt";
            this.txtTen_Yt.OldValue = null;
            this.txtTen_Yt.Size = new System.Drawing.Size(570, 13);
            this.txtTen_Yt.TabIndex = 85;
            this.txtTen_Yt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Yt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Yt.Value = ((object)(resources.GetObject("txtTen_Yt.Value")));
            // 
            // txtMa_Yt
            // 
            this.txtMa_Yt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Yt.CheckTextSearched = false;
            this.txtMa_Yt.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Yt.FieldDisplay = "Ten_Yt";
            this.txtMa_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Yt.Location = new System.Drawing.Point(97, 28);
            this.txtMa_Yt.MaxLength = 32;
            this.txtMa_Yt.Name = "txtMa_Yt";
            this.txtMa_Yt.OldValue = null;
            this.txtMa_Yt.Size = new System.Drawing.Size(111, 20);
            this.txtMa_Yt.TabIndex = 0;
            this.txtMa_Yt.TableName = "DMYT";
            this.txtMa_Yt.TextDisplay = this.txtTen_Yt;
            this.txtMa_Yt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Yt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Yt.Value = ((object)(resources.GetObject("txtMa_Yt.Value")));
            // 
            // lblMa_Sp
            // 
            this.lblMa_Sp.AutoSize = true;
            this.lblMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Sp.Location = new System.Drawing.Point(9, 52);
            this.lblMa_Sp.Name = "lblMa_Sp";
            this.lblMa_Sp.Size = new System.Drawing.Size(59, 14);
            this.lblMa_Sp.TabIndex = 84;
            this.lblMa_Sp.Text = "Công đoạn";
            // 
            // lblDesc_EN
            // 
            this.lblDesc_EN.AutoSize = true;
            this.lblDesc_EN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDesc_EN.Location = new System.Drawing.Point(9, 94);
            this.lblDesc_EN.Name = "lblDesc_EN";
            this.lblDesc_EN.Size = new System.Drawing.Size(71, 14);
            this.lblDesc_EN.TabIndex = 89;
            this.lblDesc_EN.Text = "Diễn giải (EN)";
            // 
            // lblDien_Giai
            // 
            this.lblDien_Giai.AutoSize = true;
            this.lblDien_Giai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblDien_Giai.Location = new System.Drawing.Point(9, 73);
            this.lblDien_Giai.Name = "lblDien_Giai";
            this.lblDien_Giai.Size = new System.Drawing.Size(73, 14);
            this.lblDien_Giai.TabIndex = 90;
            this.lblDien_Giai.Text = "Diễn giải (VN)";
            // 
            // txtDesc_EN
            // 
            this.txtDesc_EN.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtDesc_EN.CheckTextSearched = false;
            this.txtDesc_EN.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDesc_EN.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDesc_EN.Location = new System.Drawing.Point(97, 91);
            this.txtDesc_EN.MaxLength = 128;
            this.txtDesc_EN.Name = "txtDesc_EN";
            this.txtDesc_EN.OldValue = null;
            this.txtDesc_EN.Size = new System.Drawing.Size(687, 20);
            this.txtDesc_EN.TabIndex = 3;
            this.txtDesc_EN.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtDesc_EN.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtDesc_EN.Value = ((object)(resources.GetObject("txtDesc_EN.Value")));
            // 
            // txtDien_Giai
            // 
            this.txtDien_Giai.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtDien_Giai.CheckTextSearched = false;
            this.txtDien_Giai.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtDien_Giai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDien_Giai.Location = new System.Drawing.Point(97, 70);
            this.txtDien_Giai.MaxLength = 128;
            this.txtDien_Giai.Name = "txtDien_Giai";
            this.txtDien_Giai.OldValue = null;
            this.txtDien_Giai.Size = new System.Drawing.Size(687, 20);
            this.txtDien_Giai.TabIndex = 2;
            this.txtDien_Giai.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtDien_Giai.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtDien_Giai.Value = ((object)(resources.GetObject("txtDien_Giai.Value")));
            // 
            // grdDetail
            // 
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3,
            this.Column4});
            this.grdDetail.Font = new System.Drawing.Font("Arial", 8.25F);
            this.grdDetail.Location = new System.Drawing.Point(0, 117);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.Size = new System.Drawing.Size(796, 265);
            this.grdDetail.TabIndex = 4;
            this.grdDetail.CellRightLeaved += new System.EventHandler(this.grdDetail_CellRightLeaved);
            this.grdDetail.CellBottomLeftLeaved += new System.EventHandler(this.grdDetail_CellBottomLeftLeaved);
            this.grdDetail.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.grdDetail_CellEndEdit);
            // 
            // Column1
            // 
            this.Column1.DataPropertyName = "Ma_Sp";
            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
            this.Column1.DestinationFields = "Ten_Sp";
            this.Column1.DisabledForeColor = System.Drawing.Color.Blue;
            this.Column1.EmptyIsValid = true;
            this.Column1.FirstFilter = "SP_CT = \'S\' AND Loai_Sp = \'K\'";
            this.Column1.HeaderText = "Công đoạn";
            this.Column1.Name = "Column1";
            this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column1.SourceFields = "Ten_Sp";
            this.Column1.TableName = "DMSP";
            this.Column1.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.Column1.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "Ten_Sp";
            this.Column2.HeaderText = "Tên công đoạn";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 443;
            // 
            // Column3
            // 
            this.Column3.DataPropertyName = "He_So";
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column3.DefaultCellStyle = dataGridViewCellStyle2;
            this.Column3.HeaderText = "Hệ số";
            this.Column3.Name = "Column3";
            this.Column3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column3.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.Percent;
            this.Column3.Width = 90;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "Tien_PB";
            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
            this.Column4.DefaultCellStyle = dataGridViewCellStyle3;
            this.Column4.HeaderText = "Giá trị phân bổ";
            this.Column4.Name = "Column4";
            this.Column4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Column4.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.LocalAmount;
            this.Column4.Width = 120;
            // 
            // btnAllocate
            // 
            this.btnAllocate.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnAllocate.Location = new System.Drawing.Point(657, 430);
            this.btnAllocate.Name = "btnAllocate";
            this.btnAllocate.Size = new System.Drawing.Size(127, 23);
            this.btnAllocate.TabIndex = 8;
            this.btnAllocate.Text = "&Phân bổ";
            this.btnAllocate.UseVisualStyleBackColor = true;
            this.btnAllocate.Click += new System.EventHandler(this.btnAllocate_Click);
            // 
            // btnGetValue
            // 
            this.btnGetValue.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnGetValue.Location = new System.Drawing.Point(12, 430);
            this.btnGetValue.Name = "btnGetValue";
            this.btnGetValue.Size = new System.Drawing.Size(127, 23);
            this.btnGetValue.TabIndex = 7;
            this.btnGetValue.Text = "&Xác định giá trị";
            this.btnGetValue.UseVisualStyleBackColor = true;
            this.btnGetValue.Click += new System.EventHandler(this.btnGetValue_Click);
            // 
            // txtTTien_Nt0
            // 
            this.txtTTien_Nt0.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTTien_Nt0.BackColor = System.Drawing.Color.White;
            this.txtTTien_Nt0.Enabled = false;
            this.txtTTien_Nt0.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTTien_Nt0.ForeColor = System.Drawing.Color.Black;
            this.txtTTien_Nt0.Location = new System.Drawing.Point(125, 388);
            this.txtTTien_Nt0.Name = "txtTTien_Nt0";
            this.txtTTien_Nt0.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtTTien_Nt0.OldValue = null;
            this.txtTTien_Nt0.Size = new System.Drawing.Size(120, 20);
            this.txtTTien_Nt0.TabIndex = 5;
            this.txtTTien_Nt0.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtTTien_Nt0.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.txtTTien_Nt0.Value = ((object)(resources.GetObject("txtTTien_Nt0.Value")));
            // 
            // lblTTien_Nt0
            // 
            this.lblTTien_Nt0.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.lblTTien_Nt0.AutoSize = true;
            this.lblTTien_Nt0.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTTien_Nt0.Location = new System.Drawing.Point(9, 391);
            this.lblTTien_Nt0.Name = "lblTTien_Nt0";
            this.lblTTien_Nt0.Size = new System.Drawing.Size(107, 14);
            this.lblTTien_Nt0.TabIndex = 103;
            this.lblTTien_Nt0.Text = "Tổng giá trị phát sinh";
            // 
            // lblTTien_PB
            // 
            this.lblTTien_PB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.lblTTien_PB.AutoSize = true;
            this.lblTTien_PB.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTTien_PB.Location = new System.Drawing.Point(551, 391);
            this.lblTTien_PB.Name = "lblTTien_PB";
            this.lblTTien_PB.Size = new System.Drawing.Size(102, 14);
            this.lblTTien_PB.TabIndex = 103;
            this.lblTTien_PB.Text = "Tổng giá trị phân bổ";
            // 
            // txtTTien_PB
            // 
            this.txtTTien_PB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTTien_PB.BackColor = System.Drawing.Color.White;
            this.txtTTien_PB.Enabled = false;
            this.txtTTien_PB.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTTien_PB.ForeColor = System.Drawing.Color.Black;
            this.txtTTien_PB.Location = new System.Drawing.Point(664, 388);
            this.txtTTien_PB.Name = "txtTTien_PB";
            this.txtTTien_PB.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtTTien_PB.OldValue = null;
            this.txtTTien_PB.Size = new System.Drawing.Size(120, 20);
            this.txtTTien_PB.TabIndex = 6;
            this.txtTTien_PB.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtTTien_PB.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.ForeignAmount;
            this.txtTTien_PB.Value = ((object)(resources.GetObject("txtTTien_PB.Value")));
            // 
            // labelControl2
            // 
            this.labelControl2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.labelControl2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.labelControl2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.labelControl2.Location = new System.Drawing.Point(0, 416);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new System.Drawing.Size(796, 2);
            this.labelControl2.TabIndex = 103;
            // 
            // FormDmPBCHSPEditor
            // 
            this.AddTitleText = "Thêm bút toán phân bổ chung";
            this.ClientSize = new System.Drawing.Size(796, 465);
            this.Controls.Add(this.txtTTien_PB);
            this.Controls.Add(this.lblTTien_PB);
            this.Controls.Add(this.txtTTien_Nt0);
            this.Controls.Add(this.labelControl2);
            this.Controls.Add(this.lblTTien_Nt0);
            this.Controls.Add(this.btnGetValue);
            this.Controls.Add(this.btnAllocate);
            this.Controls.Add(this.grdDetail);
            this.Controls.Add(this.lblDesc_EN);
            this.Controls.Add(this.lblDien_Giai);
            this.Controls.Add(this.txtDesc_EN);
            this.Controls.Add(this.txtDien_Giai);
            this.Controls.Add(this.txtMa_Sp);
            this.Controls.Add(this.lblMa_Yt);
            this.Controls.Add(this.txtTen_Yt);
            this.Controls.Add(this.txtTen_Sp);
            this.Controls.Add(this.txtMa_Yt);
            this.Controls.Add(this.lblMa_Sp);
            this.EditTitleText = "Sửa bút toán phân bổ chung";
            this.Name = "FormDmPBCHSPEditor";
            this.ShowFreeFields = false;
            this.Text = "Thêm bút toán phân bổ chung";
            this.Controls.SetChildIndex(this.lblPhan_Loai, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai1, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai2, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai3, 0);
            this.Controls.SetChildIndex(this.lblMa_Sp, 0);
            this.Controls.SetChildIndex(this.txtMa_Yt, 0);
            this.Controls.SetChildIndex(this.txtTen_Sp, 0);
            this.Controls.SetChildIndex(this.txtTen_Yt, 0);
            this.Controls.SetChildIndex(this.lblMa_Yt, 0);
            this.Controls.SetChildIndex(this.txtMa_Sp, 0);
            this.Controls.SetChildIndex(this.txtDien_Giai, 0);
            this.Controls.SetChildIndex(this.txtDesc_EN, 0);
            this.Controls.SetChildIndex(this.lblDien_Giai, 0);
            this.Controls.SetChildIndex(this.lblDesc_EN, 0);
            this.Controls.SetChildIndex(this.grdDetail, 0);
            this.Controls.SetChildIndex(this.btnAllocate, 0);
            this.Controls.SetChildIndex(this.btnGetValue, 0);
            this.Controls.SetChildIndex(this.lblTTien_Nt0, 0);
            this.Controls.SetChildIndex(this.labelControl2, 0);
            this.Controls.SetChildIndex(this.txtTTien_Nt0, 0);
            this.Controls.SetChildIndex(this.lblTTien_PB, 0);
            this.Controls.SetChildIndex(this.txtTTien_PB, 0);
            ((System.ComponentModel.ISupportInitialize)(this.grdDetail)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnReset()
        {
            if (base.NewChecked)
            {
                this.txtTTien_Nt0.Value = DBNull.Value;
                this.txtTTien_PB.Value = DBNull.Value;
                if (this.oDetailTable == null)
                {
                    this.oDetailTable = this.oMethod.GetDetailTableC(-1);
                }
                DataRow row = this.oDetailTable.NewRow();
                row["He_So"] = 0;
                row["Tien_PB"] = 0;
                this.oDetailTable.Rows.Clear();
                this.oDetailTable.Rows.Add(row);
            }
            else
            {
                this.oDetailTable = this.oMethod.GetDetailTableC(base.LocalCurrentRow["Stt"]);
            }
            this.grdDetail.DataSource = new BindingSource(this.oDetailTable, this.oDetailTable.TableName);
            base.OnReset();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if ((((DateTime) base.UserDefined2) < AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) base.UserDefined2) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtMa_Yt.Text))
            {
                MessageBox.Show("Chưa nhập mã yếu tố!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtTTien_Nt0.NumericValue != this.txtTTien_PB.NumericValue)
            {
                MessageBox.Show("Tổng giá trị phân bổ phải bằng tổng giá trị phát sinh!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Dvcs"] = AppInstance.Subsidiary;
            localCurrentRow["Ma_Yt"] = this.txtMa_Yt.Value;
            localCurrentRow["Ten_Yt"] = this.txtTen_Yt.Value;
            localCurrentRow["Ma_Sp"] = this.txtMa_Sp.Value;
            localCurrentRow["Ten_Sp"] = this.txtTen_Sp.Value;
            localCurrentRow["Dien_Giai"] = this.txtDien_Giai.Value;
            localCurrentRow["Desc_EN"] = this.txtDesc_EN.Value;
            localCurrentRow["TTien_PB"] = this.txtTTien_PB.Value;
            if (!this.oMethod.SaveRowC(base.NewChecked, base.UserDefined1, base.UserDefined2, localCurrentRow, this.oDetailTable))
            {
                MessageBox.Show("Không lưu được dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (AppInstance.CostingInvoice)
            {
                this.oMethod.CreateInvoice(AppInstance.Subsidiary, base.UserDefined1, this.txtDien_Giai.Value, this.txtDesc_EN.Value, AppInstance.DefaultCurrency, AppInstance.UserName, AppInstance.PostDefault ? 1 : 0, AppInstance.LockDefault, this.CreateInvoice());
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Yt.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Yt.Value = base.LocalCurrentRow["Ma_Yt"];
            this.txtTen_Yt.Value = base.LocalCurrentRow["Ten_Yt"];
            this.txtMa_Sp.Value = base.LocalCurrentRow["Ma_Sp"];
            this.txtTen_Sp.Value = base.LocalCurrentRow["Ten_Sp"];
            this.txtDien_Giai.Value = base.LocalCurrentRow["Dien_Giai"];
            this.txtDesc_EN.Value = base.LocalCurrentRow["Desc_EN"];
            this.txtTTien_Nt0.Value = base.LocalCurrentRow["TTien_PB"];
            this.txtTTien_PB.Value = base.LocalCurrentRow["TTien_PB"];
            base.OnShow();
        }

        private void Sum()
        {
            decimal num = 0M;
            foreach (DataRow row in this.oDetailTable.Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    num += (decimal) row["Tien_PB"];
                }
            }
            this.txtTTien_PB.Value = num;
        }
    }
}

